<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META content="text/html; charset=ISO-8859-2" http-equiv="content-type">
<meta name="robots" content="index,follow">
<META NAME="Keywords" CONTENT="Base32, base 32, base 32 encoder, javascript">
<meta name="viewport" content="width=device-width, initial-scale=1">
<META NAME="Author" CONTENT="Tomasz Ostrowski">
<META name="description" content="On-line javascript hexadecimal to base 32 converter.">  
<link rel="stylesheet" type="text/css" media="only screen and (max-width: 959px)" href="./css/mobile.css" />
<link rel="stylesheet" type="text/css" media="only screen and (min-width: 960px)" href="./css/main.css" />
<script type="text/javascript" src="./js/tree.js"></script>


<script src="./js/jquery-2.1.3.min.js"></script>
<!-- <link rel="stylesheet" type="text/css" href="./css/jquery-eu-cookie-law-popup.css"/>
<script src="./js/jquery-eu-cookie-law-popup-en.js"></script> -->

<title>Hex to base32 converter</title>  
</head>
<body class="eupopup eupopup-bottomleft eupopup-style-compact">

<div id="wrap">
<div id="header">
<div id="header_l">
  <a href="../index.htm">erma0.cn</a>
</div>
<div id="header_r"><A HREF="./hex_to_base32_multi.htm" TARGET="_self"><strong>ENGLISH VERSION</strong></A><br><A HREF="./hex_to_base32_multi.php?lang=pl" TARGET="_self"><strong>WERSJA POLSKA</strong></A></div>      
</div>

<a href="../bot-trap/">
  <img src="./images/pixel.gif" border="0" alt=" " width="1" height="1">
</a>
     

<script type="text/javascript">
//<!--
    function clean_hex(input, remove_0x) {
        input = input.toUpperCase();
        
        if (remove_0x) {
          input = input.replace(/0x/gi, "");        
        }
        
        var orig_input = input;
        input = input.replace(/[^A-Fa-f0-9]/g, "");
        if (orig_input != input)
            alert ("Warning! Non-hex characters in input string ignored.");
        return input;    
    }

    /*
    RFC4648 test vectors:     
     BASE32("f" = 0x66) = "MY======"
     BASE32("fo") = "MZXQ===="
     BASE32("foo") = "MZXW6==="
     BASE32("foob") = "MZXW6YQ="
     BASE32("fooba") = "MZXW6YTB"
     BASE32("foobar") = "MZXW6YTBOI======"
    
    hex: 
    66
    666F
    666F6F
    666F6F62
    666F6F6261
    666F6F626172             
    */

    var base32_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
    function binary_to_base32(input) {
      var ret = new Array();
      var ret_len = 0;
      var i = 0;
    
      var unpadded_length = input.length;
      while (input.length % 5) {
        input[input.length] = 0;
      }
    
    	for(i=0; i<input.length; i+=5) {
    		ret += base32_chars.charAt((input[i] >> 3));
    		ret += base32_chars.charAt(((input[i] & 0x07) << 2) | ((input[i+1] & 0xc0) >> 6));
        if (i+1 >= unpadded_length) {
          ret += "======"
          break;
        }
    		ret += base32_chars.charAt(((input[i+1] & 0x3e) >> 1));       
    		ret += base32_chars.charAt(((input[i+1] & 0x01) << 4) | ((input[i+2] & 0xf0) >> 4));
        if (i+2 >= unpadded_length) {
          ret += "===="
          break;
        }        
    		ret += base32_chars.charAt(((input[i+2] & 0x0f) << 1) | ((input[i+3] & 0x80) >> 7));
        if (i+3 >= unpadded_length) {
          ret += "==="
          break;
        }        
    		ret += base32_chars.charAt(((input[i+3] & 0x7c) >> 2));
    		ret += base32_chars.charAt(((input[i+3] & 0x03) << 3) | ((input[i+4] & 0xe0) >> 5));
        if (i+4 >= unpadded_length) {
          ret += "="
          break;
        }          
    		ret += base32_chars.charAt(((input[i+4] & 0x1f))); 		
    	}
    	return ret;
    }

    function base32_encode(input, remove_0x) {
        var cleaned_hex = clean_hex(input, remove_0x);
        if (cleaned_hex.length % 2) {      
            return ["", "Error: cleaned hex string length is odd."];
        }
        var binary = new Array();
        for (var i=0; i<cleaned_hex.length/2; i++) {
            var h = cleaned_hex.substr(i*2, 2);
            binary[i] = parseInt(h,16);        
        }
        var output = binary_to_base32(binary);
        return [output, ""];
    }        
    
    function Convert() {
        var lines = document.frmConvert.hexList.value.split('\n');
        var remove_0x = document.frmConvert.chbSeparator.checked;
        var skip_comment = document.frmConvert.chbSkipComment.checked;
        var outputText = "";
        for(var i = 0;i < lines.length; i++){
            var line = lines[i].trim();
            var outputArr = base32_encode(line);
            var output = outputArr[0];
            var status = outputArr[1];
            outputText += output;
            if (skip_comment) {
              outputText += "\r\n";
            } else {
              outputText += ", " + status + "\r\n";
            }                        
        }    
        document.frmConvert.base32List.value = outputText;    
    } 

//-->
</script>


<div id="main">
<h1>Multiple hexadecimal -> base32 string converter</h1>
    <p>This form converts list of hex strings (one string per line, can be exported from Libre/OpenOffice Calc as CSV file from sheet with single columm or just by selection)
    to list of base32 strings.
    <br>
    Each output line contains base32 string (if conversion succeded) and optional comment after comma
    if conversion failed (uneven number of hex characters). This can be treated as CSV file with two columns
    and imported back to Calc ("Paste Special" option and marking comma as separator in text import dialog works too).
    </p>
          
      <form name="frmConvert" action="">
				<p>List of hex strings (one per line = 1 CSV column):</p>
			    <p>
            <textarea name="hexList" rows="10" cols="67" style="width: 550px;""></textarea>
          </p>
        <p>
          Note: all characters outside hex set will be ignored, thus "12AB34" = "12 AB 34" = "12, AB, 34", etc.
          Input is case-insensitive.
        </p>
        
        <p>Options:</p>
          <p>
            <input type="checkbox" name="chbSeparator" value="sep" checked="yes">remove "0x" groups from input
            <br>
            <input type="checkbox" name="chbSkipComment" value="skipComment" checked="yes">skip column with comment (comma and optional text after)
          </p>			
        
        <p>Output (base32 + comment, two CSV columns, second column empty = no error):</p>
			    <p>
    			    <textarea name="base32List" rows="10" cols="67" style="width: 550px;""></textarea>                    
          </p>    
			  
        <p>
          <button type=button name="btnConvert"
            onclick="Convert()">
            Convert
          </button>
			  </p>
			</form>     
  </div>
<div id="sidebar">
<h3>Sitemap</h3>

<ul id="tree0" class="tree">

    <li ><a>PROJECTS</a>
    <ul>
    <li><A HREF="../programator.htm" TARGET="_self">FLASH 49F programmer</A></li> 
    </ul>
    </li>

 
    <li><a>ONLINE TOOLS</a>
    <ul>
    <li><a href="./base64.htm" TARGET="_self">Base64 -&gt; HEX</A></li>
    <li><a href="./base32.htm" TARGET="_self">Base32 -&gt; HEX</a></li>
    <li><a href="./base32hex.htm" TARGET="_self">Base32hex -&gt; HEX</a></li>
    <li><a href="./ascii.htm" TARGET="_self">ASCII -&gt; HEX</a></li>
    <li><a href="./ascii_uN.htm" TARGET="_self">ASCII -&gt; u16/u32/u64 HEX</a></li>            
    <li><a href="./hex_to_base64.htm" TARGET="_self">HEX -&gt; Base64</a></li>
    <li><a href="./text_to_base64.htm" TARGET="_self">Text -&gt; Base64</a></li>
    <li><a href="./hex_to_base32.htm" TARGET="_self">HEX -&gt; Base32</a></li>
    <li><a href="./hex_to_base32hex.htm" TARGET="_self">HEX -&gt; Base32hex</a></li>
    <li><a href="./hex_to_ascii.htm" TARGET="_self">HEX -&gt; ASCII</a></li>
    <li><a href="./hex_to_dec.htm" TARGET="_self">HEX -&gt; DEC</a></li>	
    <li><a href="./dec_to_ascii.htm" TARGET="_self">DEC -&gt; ASCII</a></li>
    <li><a href="./bin_to_32bit_hex.htm" TARGET="_self">BIN &lt;-&gt; 32-bit hex</a></li>    
    <li><a href="./md5.htm" TARGET="_self">MD5 calculator</a></li>
    <li><a href="./sha1.htm" TARGET="_self">SHA1 calculator</a></li>    
    <li><a href="./regexp.htm" TARGET="_self">Regular exp.</a></li>
    <li><a href="./cpp_text_escape.htm" TARGET="_self">Text -&gt; Cpp</a></li>
    <li><a href="./cpp_unescape.htm" TARGET="_self">Cpp -&gt; text</a></li>
    <li><a href="./pascal_escape.htm" TARGET="_self">Text -&gt; Pascal</a></li>        
    <li><a href="./hex_to_file.htm" TARGET="_self">HEX -&gt; file</a></li>
    <li><a href="./file_to_hex.htm" TARGET="_self">File -&gt; HEX</a></li>
    <li><a href="./file_to_base64.htm" TARGET="_self">File -&gt; Base64</a></li>    
    <li><a href="./html_list_gen.htm" TARGET="_self">Text -&gt; HTML ul</a></li>
    <li><a href="./crc8.htm" TARGET="_self">CRC8</a></li>
    <li><a href="./wave_gen.htm" TARGET="_self">WAVE generator</a></li>
    <li><a href="./bin_decoder.htm" TARGET="_self">Bin decoder</a></li>
    <li><a href="./rc4.htm" TARGET="_self">RC4</a></li>          
    <li><a href="./xor.htm" TARGET="_self">XOR</a></li>
    <li><a href="./inv.htm" TARGET="_self">Inverting bits</a></li>
    <li><a href="./par_resistors.htm" TARGET="_self">Par. resistors search</a></li>
    <li><a href="./unique_str.htm" TARGET="_self">Deduplicate / sort</a></li>        
    <li><a href="./base64_to_PEM.htm" TARGET="_self">Base64 -&gt; PEM</a></li>
    <li><a href="./PEM_to_base64.htm" TARGET="_self">PEM -&gt; base64</a></li>
    <li><a href="./diskstats.htm" TARGET="_self">/proc/diskstats</a></li>    
    </ul>
    </li> 


    <li><A HREF="../contact2.htm" TARGET="_self">Contact</A></li></ul>
<script type="text/javascript">
//<!--
new tree("tree0");
//-->
</script>

<br>  
<br>  
<br>  





  <br>    

        
    
</div>


<div id="footer">




  
</div>


<br>
<div id="footer2"><p>      
            <!-- <font size="-2">&nbsp;"Cookie monsters": 5583818&nbsp;&nbsp;&nbsp;&nbsp;Parse time:&nbsp;0.000 s</font> -->

  </p>
	</div>
</div>
</body>
</html>

